From b2e4b18c2e62e28c27a00318be588b96896c0bec Mon Sep 17 00:00:00 2001 From: Jyrki Gadinger Date: Wed, 12 Feb 2025 12:33:20 +0100 Subject: [PATCH] wizard: display error message when ToS haven't been accepted yet Signed-off-by: Jyrki Gadinger --- src/gui/connectionvalidator.cpp | 9 ++++++++- src/gui/owncloudsetupwizard.cpp | 8 ++++++++ src/gui/tray/syncstatussummary.cpp | 1 + src/libsync/owncloudpropagator_p.h | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index ebe1c1af5..31467ec3f 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -221,13 +221,20 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) stat = CredentialsWrong; } else if (reply->error() != QNetworkReply::NoError) { - _errors << job->errorStringParsingBody(); + QByteArray body; + _errors << job->errorStringParsingBody(&body); const int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (httpStatus == 503) { _errors.clear(); stat = ServiceUnavailable; + } else if (httpStatus == 403) { + const auto davException = job->errorStringParsingBodyException(body); + if (davException == QStringLiteral(R"(OCA\TermsOfService\TermsNotSignedException)")) { + qCInfo(lcConnectionValidator) << "The terms of service need to be signed"; + stat = NeedToSignTermsOfService; + } } } diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index ae11ff72a..66282a067 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -31,6 +31,7 @@ #include "networkjobs.h" #include "owncloudgui.h" #include "owncloudsetupwizard.h" +#include "owncloudpropagator_p.h" #include "sslerrordialog.h" #include "wizard/owncloudwizard.h" #include "wizard/owncloudwizardcommon.h" @@ -421,10 +422,17 @@ void OwncloudSetupWizard::slotAuthError() // Provide messages for other errors, such as invalid credentials. } else if (reply->error() != QNetworkReply::NoError) { + auto davException = OCC::getExceptionFromReply(reply); + if (!_ocWizard->account()->credentials()->stillValid(reply)) { errorMsg = tr("Access forbidden by server. To verify that you have proper access, " "click here to access the service with your browser.") .arg(Utility::escape(_ocWizard->account()->url().toString())); + } else if (!davException.first.isEmpty() && davException.first == QStringLiteral(R"(OCA\TermsOfService\TermsNotSignedException)")) { + qCInfo(lcWizard) << "Terms of service not accepted yet!"; + // TODO: it would be cool to display a new wizard page containing the terms of service + errorMsg = tr("Please accept the Terms of Service with your browser and try again.") + .arg(Utility::escape(_ocWizard->account()->url().toString())); } else { errorMsg = job->errorStringParsingBody(); } diff --git a/src/gui/tray/syncstatussummary.cpp b/src/gui/tray/syncstatussummary.cpp index cd31daac9..0e5d43c92 100644 --- a/src/gui/tray/syncstatussummary.cpp +++ b/src/gui/tray/syncstatussummary.cpp @@ -14,6 +14,7 @@ #include "syncstatussummary.h" #include "accountfwd.h" +#include "accountstate.h" #include "folderman.h" #include "navigationpanehelper.h" #include "networkjobs.h" diff --git a/src/libsync/owncloudpropagator_p.h b/src/libsync/owncloudpropagator_p.h index beb150648..95e383493 100644 --- a/src/libsync/owncloudpropagator_p.h +++ b/src/libsync/owncloudpropagator_p.h @@ -69,8 +69,8 @@ inline QPair getExceptionFromReply(QNetworkReply * const return {}; } const auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - // only for BadRequest and UnsupportedMediaType - if (httpStatusCode != 400 && httpStatusCode != 415) { + // only for BadRequest, Forbidden, and UnsupportedMediaType + if (!(httpStatusCode == 400 || httpStatusCode == 403 || httpStatusCode == 415)) { return {}; } -- 2.30.2